package com.wql.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQConfig {

    private static final String QUEUE_NAME="FLOW_CONTROL_QUEUE";
    private static final String EXCHANGE_NAME="TOPIC_EXCHANGE";
    private static final String ROUTING_KEY = "user.#";

    @Bean
    public Queue queue(){
        return new Queue(QUEUE_NAME);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(EXCHANGE_NAME);
    }

    @Bean
    public Binding binding(){
       return BindingBuilder.bind(queue()).to(topicExchange()).with(ROUTING_KEY);
    }
}
